<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Article
 *
 * @author Gael
 */
class Article {
    public $id;
    public $codebare;
    public $typearticle;
    
    
    
    
    function __construct($id, $codebare, $typearticle) {
        $this->id = $id;
        $this->codebare = $codebare;
        $this->typearticle = $typearticle;
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getCodebare() {
        return $this->codebare;
    }

    public function setCodebare($codebare) {
        $this->codebare = $codebare;
    }

    public function getTypearticle() {
        return $this->typearticle;
    }
    public function getModele() {
        return $this->typearticle->getModele();
    }
    public function getType() {
        return $this->typearticle->getNomType();
    }

    public function setTypearticle($typearticle) {
        $this->typearticle = $typearticle;
    }

        static public function byId($id){
        try{
            $db= getPdo();
            $rep = $db->query("select * from article where id=$id" );
            while($data =$rep->fetch()){
                $ta= new Article($data['id'], $data['codebarre'], TypeArticle::byId($data['idtypearticle']));
            }
            
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from article  " );
            while($data =$rep->fetch()){
                $tab[$data['id']    ]=new Article($data['id'], $data['codebarre'], TypeArticle::byId($data['idtypearticle']));
                
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 
   
    
}

?>
